package com.systemic.service.impl;

import com.systemic.mapper.MindfulnessLogMapper;
import com.systemic.pojo.MindfulnessLog;
import com.systemic.service.MindfulnessLogService;
import com.systemic.vo.PageVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * @ClassName: MindfulnessLogServiceImpl
 * @Description:
 * @Author:
 * @CreateTime: 2024-01-31 16:51
 * @Version:
 **/
@Service
public class MindfulnessLogServiceImpl implements MindfulnessLogService {

    @Resource
    private MindfulnessLogMapper mindfulnessLogMapper;

    /**
     * 新增
     * @param mindfulnessLog
     * @return
     */
    @Override
    @Transactional
    public int add(MindfulnessLog mindfulnessLog) {
        int row = 0;
        Date date = new Date();
        mindfulnessLog.setGmtCreate(date);
        mindfulnessLog.setGmtModified(date);
        row = mindfulnessLogMapper.insert(mindfulnessLog)+row;
        return row;
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @Override
    @Transactional
    public int deleteList(Integer[] ids) {
        int row = 0;
        List<Integer> idList= Arrays.asList(ids);
        row = mindfulnessLogMapper.deleteBatchIds(idList)+row;
        return row;
    }

    /**
     * 修改
     * @param mindfulnessLog
     * @return
     */
    @Override
    @Transactional
    public int update(MindfulnessLog mindfulnessLog) {
        int row = 0;
        Date date = new Date();
        mindfulnessLog.setGmtModified(date);
        row = mindfulnessLogMapper.update(mindfulnessLog)+row;
        return row;
    }

    /**
     * 分页查询（根据用户id）
     * @param pageVo
     * @return
     */
    @Override
    public List<MindfulnessLog> selectByAuthor(PageVo pageVo) {
        // 获取当前页数和每页显示的数据条数
        Integer pageNo = pageVo.getPageNo();
        Integer pageSize = pageVo.getPageSize();
        // 计算OFFSET值
        Integer offset = (pageNo - 1) * pageSize;
        Integer uid = pageVo.getUid();
        return mindfulnessLogMapper.likeSelectPage(uid,offset,pageSize);
    }
}
